package com.jie.dao.impl;

import com.jie.dao.RegionDao;
import com.jie.entity.Region;
import com.jie.util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by 12904 on 2018/7/28.
 */
public class RegionDaoImpl implements RegionDao
{


    @Override
    public Region find(int areaId)
    {
        Region region = null;
        Connection conn = null;
        PreparedStatement stat = null;
        ResultSet rs = null;
        String sql = "select * from region WHERE areaId = ? ";
        conn = BaseDao.getConnection();
        try {
            stat = conn.prepareStatement(sql);
            stat.setInt(1, areaId);
            rs = stat.executeQuery();
            while (rs.next()){
                region = new Region();
                region.setAreaId(rs.getInt("areaId"));
                region.setAreaCode(rs.getString("areaCode"));
                region.setAreaName(rs.getString("areaName"));
                region.setLevel(rs.getInt("level"));
                region.setCityCode(rs.getString("cityCode"));
                region.setCenter(rs.getString("center"));
                region.setParentId(rs.getInt("parentId"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeConnection(conn,stat,rs);
        }

        return region;
    }



}
